#coding=utf8
from baseobject import BaseObject, ACTOR_CLASS
from worldexc.worldexception import (WorldException, NoWay, BadDirection,
                            NotEatable,
                            )

class WorldActor(BaseObject):
    '''Живой объект мира. Реализовано передвижение.
    '''
    
    class_type = ACTOR_CLASS
    
    def __init__(self, *args, **kargs):
        self.action_success = False
        #print args
        #print kargs
        BaseObject.__init__(self, *args, **kargs) 
    
    def forward(self):
        '''Движение прямо на одну клетку.
        '''
        try:
            self.world.move_object_direct(self)
        except NoWay:
            self.action_success = False
        except BadDirection:
            self.set_direction(self.world.get_random_direction())
        else:
            self.action_success = True
            
    def to_left(self):
        '''Поворот налево.
        '''
        try:
            new_dir = self.world.left_direction(self.get_direction())
            self.set_direction(new_dir)
        except BadDirection:
            self.set_direction(self.world.get_random_direction())
            self.action_success = False
        else:
            self.action_success = True
        
        
    def to_right(self):
        '''Поворот направо.
        '''
        new_dir = self.world.right_direction(self.get_direction())
        self.set_direction(new_dir)
    
    def __str__(self):
        return 'WorldActor XY:%s DIRECTION:'